package com.taorenqi.data.service;

import android.content.Context;

import com.taorenqi.data.common.BasePageableResponse;
import com.taorenqi.data.entity.payment.AliPayResponseEntity;
import com.taorenqi.data.entity.payment.WXPayResponseEntity;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by eric on 2017/9/3.
 */

public class PaymentDataHttpRequest extends HttpRequest {

    public static final int PAY_CONTENT_TYPE_VIP = 1;//
    public static final int PAY_CONTENT_TYPE_RECHARGE = 2;//

    private static PaymentDataHttpRequest instants;
    private PaymentDataService service;

    private PaymentDataHttpRequest(Context context) {
        super(context);
        service = retrofit.create(PaymentDataService.class);
    }

    public static PaymentDataHttpRequest getInstance(Context context){
        if (instants == null){
            instants = new PaymentDataHttpRequest(context);
        }

        return instants;
    }

    /**
     * vip-微信支付
     *
     * @param subscriber 由调用者传过来的观察者对象
     */
    public void requestWxPayForVip(Subscriber<WXPayResponseEntity> subscriber, int discussId, int toUid, String discussContent) {

        Observable observable = service.postWxPay(PAY_CONTENT_TYPE_VIP, discussId, toUid, discussContent)
                .map(new HttpResultFunc<WXPayResponseEntity>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 充值-微信支付
     *
     * @param subscriber 由调用者传过来的观察者对象
     */
    public void requestWxPayForRecharge(Subscriber<WXPayResponseEntity> subscriber, int interviewId, int toUid, String interviewContent) {

        Observable observable = service.postWxPay(PAY_CONTENT_TYPE_RECHARGE, interviewId, toUid, interviewContent)
                .map(new HttpResultFunc<WXPayResponseEntity>());

        toSubscribe(observable, subscriber);
    }

    /**
     * vip-支付宝支付
     *
     * @param subscriber 由调用者传过来的观察者对象
     */
    public void requestAliPayForVip(Subscriber<BasePageableResponse<AliPayResponseEntity>> subscriber, String attrNo,int type,String sign) {

        Observable observable = service.postAliPayVip(attrNo,type,sign)
                .map(new HttpResultFunc<BasePageableResponse<AliPayResponseEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 充值-支付宝支付
     *
     * @param subscriber 由调用者传过来的观察者对象
     */
    public void requestAliPayForGb(Subscriber<AliPayResponseEntity> subscriber, String money,int type,String sign) {

        Observable observable = service.postAliPayGb(money,type,sign)
                .map(new HttpResultFunc<BasePageableResponse<AliPayResponseEntity>>());

        toSubscribe(observable, subscriber);
    }


}
